package com.goldenautumn.prefabricate.activity.cart

import android.view.Gravity
import android.view.View
import android.view.Window
import android.view.WindowManager
import com.goldenautumn.prefabricate.R
import com.goldenautumn.prefabricate.databinding.DialogCarDiscountBinding
import qncx.external.common.widget.dialog.BaseDialog

class CarDiscountDialog constructor(private var targetView:View) : BaseDialog<DialogCarDiscountBinding>(qncx.external.common.R.style.BottomDialogs) {
    override val layoutRes: Int
        get() = R.layout.dialog_car_discount

    override fun onStart() {
        super.onStart()
        val window: Window? = dialog?.window
        // 设置对话框的位置
        val location = IntArray(2)
        // 这里的view是你想要对话框从其位置弹出的view
        targetView.getLocationOnScreen(location)
        val params: WindowManager.LayoutParams? = window?.attributes
        params?.dimAmount = dimAmount
        window?.setGravity(Gravity.LEFT or Gravity.TOP)
        params?.width = WindowManager.LayoutParams.MATCH_PARENT
        if (height > 0) params?.height = height
        else params?.height = WindowManager.LayoutParams.WRAP_CONTENT
//        params?.gravity = Gravity.BOTTOM
        params?.x = location[0] // x坐标
        params?.y = location[1] // y坐标
        window?.attributes = params
    }

    override suspend fun bindView(view: View): View {

        return view
    }
}